<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<script type="text/javascript" src="js/jquery.itextclear.js"></script>
<script type="text/javascript">
	$(document)
			.ready(
					function() {
						$(
								'input[type=text], input[type=password], input[type=url], input[type=email], input[type=number], textarea',
								'.form').iTextClear();
					});
</script>
<!-- jQplot CSS -->

<link rel="stylesheet" media="screen" href="css/Tree.css" />
<link rel="stylesheet" media="screen" href="css/docs.css" />
<!-- jQplot CSS END -->

<!-- DATATABLES CSS -->
<link rel="stylesheet" media="screen" href="lib/datatables/css/vpad.css" />
<!-- DATATABLES CSS END -->
<h1 class="page-title">外训审核 - 审核</h1>
<div class="container_12 clearfix leading">
	<section class="tabs grid_12 leading">
		<ul class="clearfix">
			<li><a href="#" class="current">厦门分公司</a></li>
		</ul>
		<section>
			<section class="clearfix" style="display: block;">
				<header class="grid_12 alpha omega"> </header>
				<h5>基本信息</h5>
				<table class="display" id="example">
					<thead>
						<tr>
							<th>培训课程</th>
							<th>开始日期(时间)</th>
							<th>结束日期(时间)</th>
							<th>培训类型</th>
							<th>地点</th>
							<th>讲师</th>
							<th>费用类型</th>
							<th>预计费用</th>
						</tr>
					</thead>
					<tbody>
						<tr class="gradeX">
							<td>${plan.title}</td>
							<td>${plan.planStartDate}</td>
							<td>${plan.planEndDate}</td>
							<td>${plan.category}</td>
							<td>${plan.classroom}</td>
							<td>${plan.outingLecturer}</td>
							<td>${plan.outingCharge}</td>
							<td>${plan.outingExpectCharge}元</td>
						</tr>
					</tbody>
				</table>
				<h5>申请对象</h5>

				<table class="display" id="example">
					<thead>
						<tr>
							<th>员工工号</th>
							<th>姓名</th>
							<th>职等职级</th>
							<th>最近培训项目</th>
						</tr>
					</thead>
					<tbody>
						<s:if test="#request.employeeTargets==null || #request.employeeTargets.size<=0">
							<tr class="gradeA">
								<td colspan="9">暂无数据</td>
							</tr>
						</s:if>
						<s:else>
							<s:iterator var="emptarget" status="sta" value="#request.employeeTargets">
								<s:if test="#sta.even">
									<tr class="gradeA">
								</s:if>
								<s:else>
									<tr class="gradeC">
								</s:else>
								<td>${emptarget.employeeinfoWork.workNo}</td>
								<td>${emptarget.employeeinfoWork.baseId.name}</td>
								<td>${emptarget.employeeinfoWork.grade.gradeName}</td>
								<td>${plan.title}</td>
								</tr>
							</s:iterator>
						</s:else>
					</tbody>
				</table>

			</section>
		</section>
	</section>
	<div class="tabs side grid_12 leading">
		<div class="clear"></div>
	</div>
	<s:if test="#request.plan.outingFeedback != null && #request.plan.outingFeedback != ''">
	<div class="container_12 clearfix"
	style="margin-left: 0px; margin-right: 0px; width: 98%"
	id="assess_body">
	<div class="tabs side grid_12">
		<h5>评价报告</h5>
		<ul class="clearfix" id="ul_tab">
			<s:if
				test="#request.plan.outingFeedback != null && #request.plan.outingFeedback.indexOf('0')>-1">
				<li><a class="current" href="javascript:void(0)"
					onclick="tabChangeEvent(0)">心得报告</a></li>
			</s:if>
			<s:if
				test="#request.plan.outingFeedback != null && #request.plan.outingFeedback.indexOf('1')>-1">
				<li><a href="javascript:void(0)" onclick="tabChangeEvent(1)">外训意见回馈单</a></li>
			</s:if>
			<s:if
				test="#request.plan.outingFeedback != null && #request.plan.outingFeedback.indexOf('2')>-1">
				<li><a href="javascript:void(0)" onclick="tabChangeEvent(2)">发票或收据复印件</a></li>
			</s:if>
			<s:if
				test="#request.plan.outingFeedback != null && #request.plan.outingFeedback.indexOf('3')>-1">
				<li><a href="javascript:void(0)" onclick="tabChangeEvent(3)">结业证书</a></li>
			</s:if>
			<s:if
				test="#request.plan.outingFeedback != null && #request.plan.outingFeedback.indexOf('4')>-1">
				<li><a href="javascript:void(0)" onclick="tabChangeEvent(4)">出差报告单</a></li>
			</s:if>
		</ul>
		<section id="assess_body_content">
			<s:if
				test="#request.plan.outingFeedback != null && #request.plan.outingFeedback.indexOf('0')>-1">
				<section style="display: block;" class="clearfix" title="心得报告">
					<div class="grid_12 alpha" id="assess_list_content_0"></div>
				</section>
			</s:if>
			<s:if
				test="#request.plan.outingFeedback != null && #request.plan.outingFeedback.indexOf('1')>-1">
				<section style="display: none;" class="clearfix" title="外训意见回馈单">
					<div class="grid_12 alpha" id="assess_list_content_1"></div>
				</section>
			</s:if>
			<s:if
				test="#request.plan.outingFeedback != null && #request.plan.outingFeedback.indexOf('2')>-1">
				<section style="display: none;" class="clearfix" title="发票或收据复印件">
					<div class="grid_12 alpha" id="assess_list_content_2"></div>
				</section>
			</s:if>
			<s:if
				test="#request.plan.outingFeedback != null && #request.plan.outingFeedback.indexOf('3')>-1">
				<section style="display: none;" class="clearfix" title="结业证书">
					<div class="grid_12 alpha" id="assess_list_content_3"></div>
				</section>
			</s:if>
			<s:if
				test="#request.plan.outingFeedback != null && #request.plan.outingFeedback.indexOf('4')>-1">
				<section style="display: none;" class="clearfix" title="出差报告单">
					<div class="grid_12 alpha" id="assess_list_content_4"></div>
				</section>
			</s:if>
		</section>
	</div>
</div>
</s:if>
</div>

<div class="container_12 clearfix leading">

	<div class="tabs side grid_6">
		<h5>历史审核</h5>
		<ul class="clearfix">
			<s:if test="#request.outingAudits != null and #request.outingAudits.size() > 1">
				<s:iterator value="#request.outingAudits" status="sta">
					<s:if test="#request.sta.index < #request.outingAudits.size() - 1">
						<li><a class="current" href="#">历史审核#<s:property
									value="#request.sta.index+1" /></a></li>
					</s:if>
				</s:iterator>
			</s:if>
			<s:else>
				<li><a class="current" href="#">没有历史记录</a></li>
			</s:else>
		</ul>
		<section>
			<s:if test="#request.outingAudits != null and #request.outingAudits.size() > 1">
				<s:iterator value="#request.outingAudits" var="audit_process" status="sta">
					<s:if test="#request.sta.index < #request.outingAudits.size() - 1">
						<section style="display: block;" class="clearfix">
							<%--<h4>2012年3月22日</h4>--%>
							<div class="grid_12 alpha">
								<hr>
								<ol class="nostyle">
									<s:iterator value="#request.audit_process" var="a">
										<li>
											<%--TODO:读审核者(审核时登录用户)--%>
											<p class="title">
												${a.auditing.auditTag}
												<button type="reset" class="button" style="float: right">
													<span style="background:url(${ctx}/images/img/accept.png)"
														class="icon">&nbsp;</span>${a.status.name}
												</button>
											</p>
											<p>${a.auditContent}</p>
										</li>
									</s:iterator>
								</ol>
							</div>
						</section>
					</s:if>
				</s:iterator>
			</s:if>
			<s:else>
				<section style="display: none;" class="clearfix">
					<div class="grid_12 alpha">没有历史审核记录</div>
				</section>
			</s:else>
		</section>
	</div>



	<div class="side grid_6">
		<h5>当前审核</h5>
		<div class="accordion">
			<s:if test="#request.outingAudits != null and #request.outingAudits.size() > 0">
				<s:iterator value="#request.outingAudits" var="current_audit_process"
					status="sta">
					<s:if test="#request.sta.index == #request.outingAudits.size() - 1">
						<s:iterator value="#request.current_audit_process" var="ad"
							status="sta4">

							<!-- 审核已通过 -->
							<s:if test="#request.ad.status.toString() == 'pass_audit'">
								<header class="current">
									<%--TODO:审核者--%>
									<h2>
										${ad.auditing.auditTag}
										<button type="reset" class="button"
											style="margin-left: 250px;">
											<span style="background:url(${ctx}/images/img/accept.png)"
												class="icon">&nbsp;</span>已审核
										</button>
									</h2>
								</header>
								<section class="clearfix" style="display: block;">${ad.auditContent}</section>
							</s:if>
							<!--未审核-->
							<s:elseif test="#request.ad.status.toString() == 'wait_audit'">
								<%--TODO:由当前登录用户来审核(这里判断当前登录用户是否可审核)--%>
								<s:if test="#request.sta4.index == -1 or 1==1">
									<header>
										<h2>${ad.auditing.auditTag}</h2>
									</header>
									<section class="clearfix">
										<h6 style="display: none;">待审核</h6>
										<div class="audit_selection_div" id="audit_selection_div_${ad.id}">
                                            <s:if test="#request.canAudit == false">
                                                <h6>非当前审核者</h6>
                                            </s:if>
                                            <s:else>
                                                <h6>审核意见</h6>
                                                <hr>
                                                <textarea rows="5" style="width: 100%; margin-bottom: 10px;" id="audit_content"></textarea>
                                                <input type="radio" name="audit_radio" value="pass_audit"> 同意
                                                <input type="radio" name="audit_radio" value="reject_audit"> 不同意
                                                <button class="button" type="button" onclick="doAudit()">
                                                    <input type="hidden" value="${ad.id}" id="audit_id">
                                                    <span class="icon" style="background:url(${ctx}/images/img/help.png)">&nbsp;</span>确定审核
                                                </button>
                                            </s:else>
										</div>
									</section>
								</s:if>
								<s:else>
									<header>
										<h2>
											${ad.auditing.auditTag}
											<button type="reset" class="button"
												style="margin-left: 250px;">
												<span
													style="background:url(${ctx}/images/img/information.png)"
													class="icon">&nbsp;</span>未审核
											</button>
										</h2>
									</header>
									<section class="clearfix"></section>
								</s:else>
							</s:elseif>

						</s:iterator>
					</s:if>
				</s:iterator>
			</s:if>
			<s:else>
				<header>
					<h2>&nbsp;没有添加审核配置</h2>
				</header>
				<section class="clearfix">&nbsp;</section>
			</s:else>
		</div>
	</div>
</div>

<div class="clear"></div>

<script type="text/javascript" src="js/Tree.js"></script>
<script type="text/javascript" src="${ctx}/js/global_util.js"></script>
<script type="text/javascript">
	var currentPlanId = ${plan.id};
	$(function() {
		//设置当前审核
		$("div.audit_selection_div").each(function(i) {
			if (i != 0) {
				$(this).prev("h6").show();
				$(this).hide();
			}
		});
	});

	function doAudit() {
		var content = $("#audit_content").val();
		if (checkNull(content)) {
			return;
		}
		//var auditStatus = $("input[type='radio'][@name='audit_radio'][checked]").val();
		var auditStatus = "";
		$("input[type='radio'][name='audit_radio']").each(function() {
			if ($(this).parent(".checked").length == 1) {
				auditStatus = $(this).val();
				return false; //退出each(相当于break, return true相当于continue)
			}
		});

		var auditId = $("#audit_id").val();
		if (auditId == "") {
			return;
		}

		if (auditStatus == null || auditStatus.length == "") {
			//alert("auditStatus="+auditStatus)
			return;
		}

        //构造一个通用的AuditBase对象
        var data = {
            "auditing.id":auditId,
            "organizationId":"${organizationId}",
            "currentAuditType":"${currentAuditType}",
            "auditing.status":auditStatus,
            "auditing.auditContent":content
        };

        if('${currentAuditType}' == "audit_organization"){
            data.organizationId = "${organizationId}";
            data.currentAuditAction = "/organization/audit_list_main.xhtml";
        }else if ('${currentAuditType}' == "audit_job_specification"){
            data.jobSpecificationId = "${jobSpecification.id}";
            data.currentAuditAction = "/rank/job_specification.xhtml?operation=audit";
        }else if ('${currentAuditType}' == "audit_duty_proxy") {
            data.proxyId = "${proxy.id}";
            data.who = "${who}";
            data.currentAuditAction = "/rank/job_specification.xhtml?operation=audit";
            refreshMainContent("${ctx}/duty_proxy/audit.xhtml", data);
        }else if('${currentAuditType}'=="audit_contract_version"){
            data.versionId = "${versionId}";
            data.currentAuditAction = "/contract/version.xhtml?operation=audit";
        }else if ('${currentAuditType}' == "audit_invite_apply") {
            data.inviteApplyId = "${inviteApply.id}";
            data.currentAuditAction = "/invite/invite_list.xhtml?p=audit";
		} else if('${currentAuditType}'=="audit_contract_sign"){
            data.currentAuditAction = "/contract/conAudit.xhtml";
        } else if('${currentAuditType}'=="audit_transaction_organization"){
            data.currentAuditAction = "/transaction/organization_main.xhtml";
        } else if('${currentAuditType}'=="audit_transaction_other"){
            if("${type}" == "promotion"){
                data.currentAuditAction = "/transaction/promotion_main.xhtml";
            }else{
                data.currentAuditAction = "/transaction/demotion_main.xhtml";
            }
        }else if('${currentAuditType}'=="audit_financial_report_form"){
            data.currentAuditAction = "/sign/financial-report-form.xhtml";
        }else if('${currentAuditType}'=="audit_financial_payment_apply_form"){
            data.currentAuditAction = "/sign/financial-payment-apply-form.xhtml";
        }else if('${currentAuditType}'=="audit_financial_in_bill_form"){
            data.currentAuditAction = "/sign/financial-in-bill-form.xhtml";
        }else if('${currentAuditType}'=="audit_administration_evection_apply_form"){
            data.currentAuditAction = "/sign/administration-evection-apply-form.xhtml";
        }else if('${currentAuditType}'=="audit_administration_evection_report_form"){
            data.currentAuditAction = "/sign/administration-evection-report-form.xhtml";
        }else if('${currentAuditType}'=="audit_administration_evection_cost_report_form"){
            data.currentAuditAction = "/sign/administration-evection-cost-apply-form.xhtml";
        }else if('${currentAuditType}'=="audit_administration_out_apply_form"){
            data.currentAuditAction = "/sign/administration-out-apply-form.xhtml";
        }else if('${currentAuditType}'=="audit_leave_office"){
            data.currentAuditAction = "/leave/apply-audit-main.xhtml";
        }else if('${currentAuditType}'=="audit_train_outing_plan_close"){
            data.currentAuditAction = "/train/outing_close_audit_main.xhtml";
        }

		//for(var p in data){alert(p+"----"+data[p])}
		refreshMainContent("${ctx}/authority/audit-base.xhtml", data);
	}
	$(document).ready(function() {
		$("#backlayout").hide();
		<s:if test="#request.plan.outingFeedback != null && #request.plan.outingFeedback.indexOf('0')>-1">
		loadAssessContent(currentPlanId, '心得报告', 0);
		</s:if>
		<s:if test="#request.plan.outingFeedback != null && #request.plan.outingFeedback.indexOf('1')>-1">
		loadAssessContent(currentPlanId, '外训意见回馈单', 1);
		</s:if>
		<s:if test="#request.plan.outingFeedback != null && #request.plan.outingFeedback.indexOf('2')>-1">
		loadAssessContent(currentPlanId, '发票或收据复印件', 2);
		</s:if>
		<s:if test="#request.plan.outingFeedback != null && #request.plan.outingFeedback.indexOf('3')>-1">
		loadAssessContent(currentPlanId, '结业证书', 3);
		</s:if>
		<s:if test="#request.plan.outingFeedback != null && #request.plan.outingFeedback.indexOf('4')>-1">
		loadAssessContent(currentPlanId, '出差报告单', 4);
		</s:if>
	});
	//显示评论列表 
	function tabChangeEvent(idx) {
		$("#ul_tab li a").removeClass("current");
		$("#ul_tab").find("li").each(function(i) {
			if (idx == i) {
				$(this).find("a").addClass("current");
			}
		});

		var wtitle = "";
		$("#assess_body_content section").attr("style", "display:none");
		$("#assess_body_content").find("section").each(function(i) {
			if (idx == i) {
				$(this).attr("style", "display:block");
				wtitle = $(this).attr("title");
			}
		});

		loadAssessContent(currentPlanId, wtitle, idx);
	}

	function loadAssessContent(planId, weightTitle, tabIdx) {
		var url = "/train/train_assess_outing_employee.xhtml";
		var data = {
			"planId" : planId,
			"weightTitle" : weightTitle
		};
		//refreshListContent(url, data);
		$.ajax(url, {
			type : "POST",
			//data:{"organizationId":organizationId},
			data : data,
			dataType : "html",
			cache : false,
			success : function(a) {
				var obj = $("#assess_list_content_" + tabIdx);
				obj.html("");
				obj.append(a);
			},
			complete : function() {
			}
		});
	}
</script>